//
//  SQLManager.swift
//  weibo
//
//  Created by songhuipan on 16/4/28.
//  Copyright © 2016年 songhuipan. All rights reserved.
//

import Foundation
private let sqlName = "status.db"
class SQLManager {
    // 定义全局访问点
    static let sharedTools:SQLManager = SQLManager()
    
    let queue:FMDatabaseQueue
    
    private init(){
        // 获得路径
        var path = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true).last!
        path = (path as NSString).stringByAppendingPathComponent(sqlName)
        // 创建数据库连接
        queue = FMDatabaseQueue(path: path)
        
        creatTable()
    }
    func creatTable(){
        let sql = "CREATE TABLE IF NOT EXISTS T_Status (" +
            "statusId integer PRIMARY KEY NOT NULL," +
            "status text," +
        "userId text) ;"
        queue.inDatabase { (db) -> Void in
            
            if db.executeStatements(sql) {
                print("创建数据库表成功了")
            }else {
                print("创建数据库表失败了")
            }
        }
        
    }
}
































